﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace Common
{
   public  class OperateConfig
    {

       public static string GetClientVersion()
       {
           IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
           string config = myini.ReadString("SERVERCONFIG", "ClientVersion", "1.00");
           if (config=="1.0")
           {
               myini.WriteString("SERVERCONFIG", "ClientVersion", "1.00");
           }
           return config;
       }

       
        public static string[] GetAcceptServerConfig()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            string[] config = new string[10];
            config[0] = myini.ReadString("SERVERCONFIG", "PositionServerIP", "127.0.0.1");
            config[1] = myini.ReadString("SERVERCONFIG", "AcceptServerIp", "127.0.0.1");
            config[2] = myini.ReadString("SERVERCONFIG", "AcceptServerWebIp", "127.0.0.1");
            config[3] = myini.ReadString("SERVERCONFIG", "PhoneNumber", "18602789588");
 
            config[4] = myini.ReadString("DBCONFIG", "DataBaseName", "TaxiDispatchSystem");
            config[5] = myini.ReadString("DBCONFIG", "ServerName", "127.0.0.1");
            config[6] = myini.ReadString("DBCONFIG", "UserID", "root");
            config[7] = myini.ReadString("DBCONFIG", "PassWord", "123456");

            config[8] = myini.ReadString("SERVERCONFIG", "MaxTcpConnetion", "10000");
            config[9] = myini.ReadString("SERVERCONFIG", "TcpBufferSize", "1");

            return config;
        }

        /// <summary>
        /// Save AcceptServer Config[]  0--PositionServerIP ,1--AcceptServerIp
        /// </summary>
        /// <param name="config"></param>
        public static void SaveAcceptServerConfig(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("SERVERCONFIG", "PositionServerIP", config[0]);
            myini.WriteString("SERVERCONFIG", "AcceptServerIp", config[1]);
            myini.WriteString("SERVERCONFIG", "AcceptServerWebIp", config[2]);
            myini.WriteString("SERVERCONFIG", "PhoneNumber", config[3]);
            myini.WriteString("SERVERCONFIG", "MaxTcpConnetion", config[4]);
            myini.WriteString("SERVERCONFIG", "TcpBufferSize", config[5]); 
        }



        /// <summary>
        /// server Save userversion
        /// </summary>
        public static string GetTaxiClientVersion()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            string version = myini.ReadString("SERVERCONFIG", "TaxiClientVersion", "1.0");
            if(version=="1.0")
            {
               SaveTaxiClientVersion(version);
            }
            return version;
        }

        /// <summary>
        /// server Save userversion
        /// </summary>
        public static void SaveTaxiClientVersion(string version)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("SERVERCONFIG", "TaxiClientVersion", version);
        }


        /// <summary>
        /// 0-DataBaseName,1-ServerName,2-UserID，3-PassWord
        /// </summary>
        /// <param name="config"></param>
        public static void SaveAcceptServerDataBaseConfig(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("DBCONFIG", "DataBaseName", config[0]);
            myini.WriteString("DBCONFIG", "ServerName", config[1]);
            myini.WriteString("DBCONFIG", "UserID", config[2]);
            myini.WriteString("DBCONFIG", "PassWord", config[3]);

        }

 
        public static string GetCenterPhoneNumber()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            return myini.ReadString("SERVERCONFIG", "PhoneNumber", "18602789588");
        }

 
 
        /// <summary>
        /// Client Save ServerIp
        /// </summary>
        public static string GetOffSetLongitude()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            return myini.ReadString("SERVERCONFIG", "OffSetLongitude", "00005723");
        }


        /// <summary>
        /// Client Save ServerIp
        /// </summary>
        public static string GetOffSetLatitude()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            return myini.ReadString("SERVERCONFIG", "OffSetLatitude", "00002287");

        }

        public static void SaveTimingConfig(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("SERVERCONFIG", "AddGpsToQuequeTime", config[0]);
            
            myini.WriteString("SERVERCONFIG", "UpdateDeviceInfoToDBTime", config[1]);
            myini.WriteString("SERVERCONFIG", "ClearDeviceTime", config[2]);
            myini.WriteString("SERVERCONFIG", "DeviceDropTime", config[3]);
            myini.WriteString("SERVERCONFIG", "MaxGpsInfoCountInOneData", config[4]);
            myini.WriteString("SERVERCONFIG", "SaveGpsToDatabaseTime", config[5]);
        }

        public static string[] GetTimingConfig()
        {
            string[] config = new string[6];
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            config[0] = myini.ReadString("SERVERCONFIG", "AddGpsToQuequeTime", "60");
            config[1] = myini.ReadString("SERVERCONFIG", "UpdateDeviceInfoToDBTime", "60");
            config[2] = myini.ReadString("SERVERCONFIG", "ClearDeviceTime", "5");
            config[3] = myini.ReadString("SERVERCONFIG", "DeviceDropTime", "5");
            config[4] = myini.ReadString("SERVERCONFIG", "MaxGpsInfoCountInOneData", "75");
            config[5] = myini.ReadString("SERVERCONFIG", "SaveGpsToDatabaseTime", "10");
            if (config[0] == "60" && config[1] == "60" &&
                config[2]=="5" && config[3]=="5"
                && config[5]=="75")
            {
                SaveTimingConfig(config);
            }
            return config;
        }
    }
}
